//
//  XIUtilities.h
//  XI Engine
//
//  Created by Balazs Faludi on 03.06.09.
//  Copyright 2009 Balazs Faludi. All rights reserved.
//

// Some useful functions.

#ifndef XIUtilities_h
#define XIUtilities_h

#define DEGREES_TO_RADIANS(x) (3.14159265358979323846 * x / 180.0)
#define RANDOM_FLOAT_BETWEEN(x, y) (((float) rand() / RAND_MAX) * (y - x) + x)

// Define XILog as an alias to NSLog when debugging is turned on, else define it as nothing.
#ifdef kXIDebugMode
#define XILog(format, ...) NSLog(format, ## __VA_ARGS__)
#else
#define XILog(format, ...)
#endif

#import "XIBase.h"

static inline float min(float a, float b)
{
	if(a < b){return a;}
	return b;
}

static inline float max(float a, float b)
{
	if(a > b){return a;}
	return b;
}

static inline float sq(float a)
{
	return a * a;
}

static inline float limit(float x, float min, float max)
{
	if(x < min) return min;
	if(x > max) return max;
	return x;
}

static inline float deadZone(float x, float min, float max)
{
	if(x>min && x<max) return (min + max) * 0.5;
	return x;
}

static inline XIFloat XIGetRandomAngle() {
	return (XIFloat)(rand() % 360) * kXIDegToRad;
}

static inline XIFloat XIGetRandomInt(int from, int to) {
	int diff = to - from;
	return (rand() % diff) + from;
}

static inline XIFloat XIGetRandomFloat(XIFloat from, XIFloat to) {
	XIFloat nullOne = (XIFloat)rand() / (XIFloat)RAND_MAX;
	return nullOne * (to - from) + from;
}

#endif